<!--
*
* Copyright 2015 HISP Tanzania
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
* @since 2015
* @author Joseph Chingalo profschingalo@gmail.com>
*
*
-->
<ion-header>

  <ion-navbar [color]="(colorSettings$ |async).colorAttributes.main">
    <ion-title>
      <span [translate]="'Event capture'"></span>
    </ion-title>
  </ion-navbar>

</ion-header>

<ion-content>
  <ion-grid>
    <ion-row>
      <ion-col>
        <div class="item-card" color="font-color" padding-top padding-bottom ion-button clear full text-center
          text-capitalize (tap)="openOrganisationUnitTree()">
          <img class="side-menu-icon" [src]="icons.orgUnit" />&nbsp;&nbsp;
          <span *ngIf="!selectedOrgUnit || !selectedOrgUnit.name" [translate]="organisationUnitLabel"></span>
          <span *ngIf="selectedOrgUnit && selectedOrgUnit.name"> {{ selectedOrgUnit.name }}</span>
        </div>
        <div class="item-card" color="font-color" padding-top padding-bottom ion-button clear full text-center
          text-capitalize (tap)="openProgramList()">
          <img class="side-menu-icon" [src]="icons.program" />&nbsp;&nbsp;
          <span *ngIf="!selectedProgram || !selectedProgram.name " [translate]="programLabel"></span>
          <span *ngIf="selectedProgram && selectedProgram.name">{{ selectedProgram.name }}</span>
        </div>
        <div *ngIf="programCategoryCombo && programCategoryCombo.id ">
          <div *ngIf="isProgramDimensionApplicable">
            <div *ngFor="let category of programCategoryCombo.categories;let categoryIndex = index">
              <div (tap)="openDataDimensionSelection(category)" class="item-card-category" color="font-color" full
                text-center text-wrap>
                <div style="padding-bottom: 5px;">
                  <b>{{ category.name }}</b>
                </div>
                <div *ngIf="selectedDataDimension[categoryIndex]">{{ selectedDataDimension[categoryIndex].name }}</div>
                <div *ngIf="!selectedDataDimension[categoryIndex]">
                  <span [translate]="'Touch to select option'"></span>
                </div>
              </div>
            </div>
          </div>
          <div class="item-card" padding-top padding-bottom *ngIf="!isProgramDimensionApplicable">
            <warning [warningMessage]="translationMapper[programDimensionNotApplicableMessage]"></warning>
          </div>
        </div>
        <div *ngIf="isFormReady">
          <div class="event-storage-status">
            <span>
              <b>
                <span [translate]="'Synced'"></span>
              </b> : {{ storageStatus.online }}
              <b>
                <span [translate]="'Not synced'"></span>
              </b> : {{storageStatus.offline }}

            </span>
            <br>
            <span *ngIf="showEventConflictHandler" margin-left>&nbsp;&nbsp;
              <event-conflict-handler (successEventConflictHandle)="onSuccessEventConflictHandle($event)"
                (successDiscovering)="onSuccessDiscoveringEvents($event)" [eventConflictHandler]="eventConflictHandler"></event-conflict-handler>
            </span>

          </div>

          <div class="item-card" (click)="hideAndShowColumns()" color="font-color" padding-top padding-bottom
            ion-button clear text-center text-capitalize icon-start>
            <ion-icon name="ios-eye" color="icon-color"></ion-icon>
            <span [translate]="'Columns'"></span>
          </div>
          <div class="item-card" (click)="goToEventRegister()" color="font-color" padding-top padding-bottom ion-button
            clear text-center text-capitalize icon-start>
            <ion-icon name="add" color="icon-color"></ion-icon>
            <span [translate]="'Add'"></span>
          </div>
        </div>

      </ion-col>
    </ion-row>
    <div *ngIf="isFormReady">
      <div *ngIf="isLoading">
        <loading [loadingSize]="'large'" [loadingMessage]="loadingMessage"></loading>
      </div>
      <div *ngIf="!isLoading" class="over-flow-container">
        <ion-row>
          <ion-col>
            <div *ngIf="tableLayout">
              <table class="table table-bordered" width="100%">
                <thead *ngIf="tableLayout && tableLayout.headers">
                  <tr>
                    <th *ngFor="let header of tableLayout.headers">{{ header}}</th>
                  </tr>
                </thead>
                <tbody *ngIf="tableLayout.rows">
                  <tr [ngStyle]="{'background-color': '#F4F4F4' }" *ngFor="let row of tableLayout.rows;let currentIndex = index"
                    (click)="goToEventView(currentIndex)">
                    <td *ngFor="let data of row">
                      {{ data }}
                    </td>
                  </tr>
                  <tr *ngIf="tableLayout.rows.length == 0">
                    <td colspan="100%">
                      <span [translate]="'There no data at the moment'"></span>
                    </td>
                  </tr>
                </tbody>
              </table>
            </div>
          </ion-col>
        </ion-row>
      </div>
    </div>
  </ion-grid>
</ion-content>
